<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/mui.picker.css" />
		<link rel="stylesheet" type="text/css" href="../css/mui.poppicker.css"/>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <h1 class="mui-title">领用扫码</h1>
		</header>
		<div class="mui-content">
			<form class="mui-input-group">
			    <div class="mui-input-row">
			        <label>出库日期</label>
			    	<input type="date" class="mui-input-clear" name="chukuDate" id="chukuDate">
			    </div>
			    <div class="mui-input-row">
			        <label>仓库类别</label>
			        <input type="text" class="mui-input-clear" id="cangkuId"  placeholder="请选择仓库">
			        <input type="hidden"  id="kuweiId" name="kuweiId" value="">
			    </div>
			    <div class="mui-input-row">
			        <label>调入仓库</label>
			        <input type="text" class="mui-input-clear" id="kuweiIdrus" placeholder="请选择库位" readonly="readonly">
			        <input type="hidden" name="kuweiIdru" id="kuweiIdru" />
			        <input type="hidden" class="mui-input-clear" id="planId">
			    </div>
			    
			     <div class="mui-input-row">
			        <label>产品编码</label>
			        <input type="text" class="mui-input-clear" id="productId"  readonly="readonly">
			        <input type="hidden" name="juanhao" id="juanhao" value=""/>
			    </div>
			    <div class="mui-input-row">
			    	<label>备注</label>
			    	<input type="text" class="mui-input-clear" name="memo" id="memo">
			    </div>
			    <div class="mui-input-row">
			    	<label for="">出库信息</label>
			    </div>
			    <div id="chukuData">
			    	
			    </div>
			   
			    <div class="mui-button-row">
			        <button type="button" class="mui-btn mui-btn-primary" id="submit" >确认出库</button>
			        <!--<button type="button" class="mui-btn mui-btn-primary" id="submit1" >模拟</button>-->
			    </div>
			</form>
		</div>
		<script src="../config.js"></script>
		<script src="../js/mui.js"></script>
		<script type="text/javascript" src="../js/mui.picker.js"></script>
		<script type="text/javascript" src="../js/mui.poppicker.js"></script>
		<script src="../js/scaner.js"></script>
		<script type="text/javascript" src="../js/jquery.1.9.1.js"></script>
		<script src="../js/app.js"></script>
		<script type="text/javascript">
			mui.init();
			var picker = new mui.PopPicker();
			document.querySelector("#cangkuId").addEventListener("tap",function(){
				picker.setData(getMlCangku());
		  		picker.show(function(items){
	            	document.getElementById('cangkuId').value=items[0].value;
	            	document.getElementById('kuweiId').value=items[0].id;
	          	});
	       });
	       document.querySelector("#kuweiIdrus").addEventListener("tap",function(){
				picker.setData(suppierRc());
		  		picker.show(function(items){
	            	document.getElementById('kuweiIdrus').value=items[0].value;
	            	document.getElementById('kuweiIdru').value=items[0].id;
	          	});
	       });
	       
	        document.querySelector("#submit").addEventListener("tap",function(){
	         	var chukuDate=document.getElementById('chukuDate').value;
	         	var kuweiId=document.getElementById('kuweiId').value;
	         	var kuweiIdru=document.getElementById('kuweiIdru').value;
	         	var planId=document.getElementById('planId').value;
	         	var juanhao=document.getElementById('juanhao').value;
	         	var productId=document.getElementById('productId').value;
	         	var memo=document.getElementById('memo').value;
	         	var submitinfo={chukuDate:chukuDate,kuweiId:kuweiId,kuweiIdru:kuweiIdru,planId:planId,juanhao:juanhao,productId:productId,memo:memo};
	         	ACChukuSaveByJuan(submitinfo, function(err) {
					if (err) {
						plus.nativeUI.toast(err);
						return;
					}
				});
	         });
			mui.plusReady(function(){
				initMe();
				window.addEventListener('comfirmPageAC',function(event){
					var productId=event.detail.productId;
					var planId=event.detail.planId;
					document.getElementById('productId').value=productId;
	            	document.getElementById('planId').value=planId;
	            	document.getElementById('juanhao').value='';
	            	document.getElementById('chukuData').innerHTML='';
				});
				plus.key.addEventListener('keyup',function(e){
					console.log("keydown: "+e.keyCode);
					if(e.keyCode==224){
						var result=getCode();
						var juanhao=document.getElementById('juanhao').value;
						var juanArr=juanhao.split(',');
						var index=$.inArray(result,juanArr);
						if(index>=0){
							mui.alert('该布卷已扫描');
							return;
						}
						var data=getMlDataChu(result);
						if(data.productId !=document.getElementById('productId').value){
			        		mui.alert('产品编码不一致');
			        		return ;
			        	}
			            document.getElementById('juanhao').value=juanhao+result+',';
			            doCodeData(data);
					}
					if(e.keyCode==4){
						mui.back();
					}
					if(e.keyCode==5){
						mui.trigger(document.getElementById('submit'),'tap');
					}
				},false);
			});
			function doCodeData(data){
				console.log(JSON.stringify(data));
				//判断之前的扫描结果有没有同缸号的，
				var id=document.getElementById(data.ganghao);
				var str='';
				if(id!=null){
					var elelenth=id.getElementsByClassName('length')[0];
					var eleweight=id.getElementsByClassName('weight')[0];
					var elejuan=id.getElementsByClassName('juan')[0];
					var length=parseFloat(elelenth.innerHTML)+parseFloat(data.cntL);
					var weight=parseFloat(eleweight.innerHTML)+parseFloat(data.cnt);
					var juan=parseInt(elejuan.innerHTML)+1;
					elelenth.innerHTML=length;
					eleweight.innerHTML=weight;
					elejuan.innerHTML=juan;
				}else{
					str='<div class="mui-input-row rukumingxi" id="'+data.ganghao+'">缸号:<span class="ganghao">'+data.ganghao+'</span>,长度:<span class="length">'+data.cntL+'</span>,重量:<span class="weight">'+data.cnt+'</span>,卷数:<span class="juan">1</span></div>';
					console.log(str);
					$('#chukuData').append(str);
				}
			}
		</script>
		
	</body>

</html>